package com.javasm.controller.MisMannageController;

import com.alibaba.fastjson.JSON;
import com.javasm.entity.MisMannageEntity.ReturnCode;
import com.javasm.entity.MisMannageEntity.ReturnEntity;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;
import java.io.PrintWriter;

/**
 * @author:JAVASM
 * @description:
 * @date:10:01
 * @version:0.1
 * @since:jdk11
 */
@WebServlet("/logout")
public class LoginOutServlet extends BaseServlet {
    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        req.setCharacterEncoding("utf-8");
        ReturnEntity re = new ReturnEntity();
        HttpSession session = req.getSession();
        //登录访问控制
        session.removeAttribute("loginUser");
        //权限访问控制  展示菜单
        session.removeAttribute("userRoles");

        re.setRetCode(ReturnCode.LOGOUT_OK.getCode());
        re.setRetMsg(ReturnCode.LOGOUT_OK.getMsg());
        resp.setContentType("text/html;charset=utf-8");
        PrintWriter pw = resp.getWriter();
        String res = JSON.toJSONString(re);
        pw.print(res);
        pw.flush();
        pw.close();
    }
}
